{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://raw.githubusercontent.com/Qiskit/qiskit-tutorials/master/images/qiskit-heading.png\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"500 px\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## _*Quantum World*_ \n",
    "\n",
    "The latest version of this notebook is available on https://github.com/QISKit/qiskit-tutorial.\n",
    "\n",
    "***\n",
    "### Contributors\n",
    "Jay Gambetta and Ismael Faro"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-25T16:48:16.163745Z",
     "start_time": "2018-09-25T16:48:15.794756Z"
    }
   },
   "outputs": [],
   "source": [
    "from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit\n",
    "from qiskit import execute\n",
    "from qiskit import IBMQ\n",
    "from qiskit.tools.jupyter import *\n",
    "from qiskit.providers.ibmq import least_busy\n",
    "# import basic plot tools\n",
    "from qiskit.tools.visualization import plot_histogram, circuit_drawer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "IBMQ.load_accounts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<IBMQBackend('ibmqx4') from IBMQ()>,\n",
       " <IBMQBackend('ibmq_16_melbourne') from IBMQ()>,\n",
       " <IBMQBackend('ibmq_qasm_simulator') from IBMQ()>]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IBMQ.backends()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-25T16:48:28.738800Z",
     "start_time": "2018-09-25T16:48:19.990885Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The least busy backend is ibmqx4\n"
     ]
    }
   ],
   "source": [
    "backend = least_busy(IBMQ.backends(simulator=False))\n",
    "print(\"The least busy backend is \" + backend.name())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-25T16:48:40.095856Z",
     "start_time": "2018-09-25T16:48:39.667560Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c69ac48bc2fc4f7ca2fad4a11161ffc1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HTML(value=\"<p style='font-size:16px;'>Job Status : job is being initialized </p>\"),))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%qiskit_job_status\n",
    "q = QuantumRegister(2)\n",
    "c = ClassicalRegister(2)\n",
    "qc = QuantumCircuit(q, c)\n",
    "qc.h(q[0])\n",
    "qc.cx(q[0], q[1])\n",
    "qc.measure(q, c)\n",
    "job_exp = execute(qc, backend=backend, shots=1024, max_credits=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-25T16:57:55.451595Z",
     "start_time": "2018-09-25T16:57:54.981066Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You have made entanglement!\n"
     ]
    }
   ],
   "source": [
    "plot_histogram(job_exp.result().get_counts(qc))\n",
    "print('You have made entanglement!')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The circuit that was run on the machine is"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-09-25T16:57:57.758850Z",
     "start_time": "2018-09-25T16:57:56.558305Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"word-wrap: normal;white-space: pre;line-height: 15px;\">         ┌───┐        ┌─┐\n",
       "q0_0: |0>┤ H ├──■─────┤M├\n",
       "         └───┘┌─┴─┐┌─┐└╥┘\n",
       "q0_1: |0>─────┤ X ├┤M├─╫─\n",
       "              └───┘└╥┘ ║ \n",
       " c0_0: 0 ═══════════╬══╩═\n",
       "                    ║    \n",
       " c0_1: 0 ═══════════╩════\n",
       "                         </pre>"
      ],
      "text/plain": [
       "<qiskit.tools.visualization._text.TextDrawing at 0x115f7bda0>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qc.draw()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
